package org.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.ssm.entity.User;
import org.ssm.mapper.UserMapper;
import org.ssm.service.UserService;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;

@Service("UserService")
public class UserImpl implements UserService {

	Log log = LogFactory.getLog(UserImpl.class); 
	@Autowired
	private UserMapper userMapper;
	public int login(User user) {
		if(StringUtils.isEmpty(user) ||
		   StringUtils.isEmpty(user.getUserName()) ||
		   StringUtils.isEmpty(user.getPassWord())){
			log.error("账号或者密码错误");
			System.out.println("账号或者密码错误");
			return -1;
		}
		return userMapper.login(user);
	}

	public User findOne(User user) {
		User user1 = userMapper.findOne(user);
		if(StringUtils.isEmpty(user1)){
			log.error("没找到");
			System.out.println("没找到");
			return null;
		}
		return user1;
	}

	public List<User> findAll(User user) {
		return userMapper.findAll(user);
	}

	public int delete(User user) {
		return userMapper.delete(user);
	}

	public int update(User user) {
		return userMapper.update(user);
	}

}